package org.yelongframework.excel.data.fill.sheet.mode.simple;

import org.yelongframework.excel.data.fill.sheet.SheetDataFillException;
import org.yelongframework.excel.data.fill.sheet.SheetDataFillMode;
import org.yelongframework.excel.data.fill.sheet.SheetDataFillScheme;

/**
 * 简单工作表数据填充属性
 * 
 * @since 1.0.0
 */
public class SimpleSheetDataFillScheme extends SheetDataFillScheme {

	/** 行索引 */
	private int rowIndex;

	/** 列索引 */
	private int columnIndex;

	/** 数据提供者 */
	private SimpleSheetDataFillDataSupplier dataSupplier;

	// ==================================================构造器==================================================

	public SimpleSheetDataFillScheme() {
		super(SheetDataFillMode.SIMPLE);
	}

	/**
	 * @param rowIndex     行索引
	 * @param columnIndex  列索引
	 * @param dataSupplier 数据提供者
	 */
	public SimpleSheetDataFillScheme(int rowIndex, int columnIndex) {
		this(rowIndex, columnIndex, (SimpleSheetDataFillDataSupplier) null);
	}

	/**
	 * @param rowIndex     行索引
	 * @param columnIndex  列索引
	 * @param dataSupplier 数据提供者
	 */
	public SimpleSheetDataFillScheme(int rowIndex, int columnIndex, Object value) {
		this(rowIndex, columnIndex, () -> value);
	}

	/**
	 * @param rowIndex     行索引
	 * @param columnIndex  列索引
	 * @param dataSupplier 数据提供者
	 */
	public SimpleSheetDataFillScheme(int rowIndex, int columnIndex, SimpleSheetDataFillDataSupplier dataSupplier) {
		this();
		this.rowIndex = rowIndex;
		this.columnIndex = columnIndex;
		this.dataSupplier = dataSupplier;
	}

	// ==================================================获取/设置==================================================

	/**
	 * @return 行索引
	 */
	public int getRowIndex() {
		return rowIndex;
	}

	/**
	 * @param rowIndex 行索引
	 */
	public void setRowIndex(int rowIndex) {
		this.rowIndex = rowIndex;
	}

	/**
	 * @return 列索引
	 */
	public int getColumnIndex() {
		return columnIndex;
	}

	/**
	 * @param columnIndex 列索引
	 */
	public void setColumnIndex(int columnIndex) {
		this.columnIndex = columnIndex;
	}

	/**
	 * @return 数据提供者
	 */
	public SimpleSheetDataFillDataSupplier getDataSupplier() {
		return dataSupplier;
	}

	/**
	 * @param dataSupplier 数据提供者
	 */
	public void setDataSupplier(SimpleSheetDataFillDataSupplier dataSupplier) {
		this.dataSupplier = dataSupplier;
	}

	/**
	 * @param value 数据值
	 */
	public void setDataValue(Object value) {
		setDataSupplier(() -> value);
	}

	// ==================================================校验==================================================

	@Override
	public void check() throws SheetDataFillException {
		if (rowIndex < 0) {
			throw new SheetDataFillException("rowIndex不能小于0");
		}
		if (columnIndex < 0) {
			throw new SheetDataFillException("columnIndex不能小于0");
		}
		if (null == dataSupplier) {
			throw new SheetDataFillException("dataSupplier不能为空");
		}
	}

}
